<?php

class payment_driver_vlcards extends a_base_payment_driver {

    private $selected_card = NULL;
    private $allowed_cards = array(
        'visa' => 'VISA',
        'master' => 'Master Card',
        'amex' => 'American Express',
        'ncl' => 'Northern Cash Link Card',
        'nla' => 'Northern Link Account'
    );

    public function __construct(stdClass $driver_data_row) {
        parent::__construct($driver_data_row);
    }

    public function validate_payment() {
        $card_name = $this->_post("vlcards_select");
        $this->selected_card = $card_name;
        if (in_array($card_name, array_keys($this->allowed_cards))) {
            return $this->allowed_cards[$this->selected_card];
        } else {
            $this->error_msg = "Invalid Card";
            return FALSE;
        }
    }

    public function write_transaction() {
        $this->db()
                ->set('order_id', $this->order_object->id)
                ->set('card_name', $this->allowed_cards[$this->selected_card])
                ->insert('payment_driver_vlcards_transaction');
    }

    public function get_payment_transactional_info(order_m_order $obj) {
        $query = $this->db()->where("order_id", $obj->id)->get("payment_driver_vlcards_transaction");
        if ($query->num_rows()) {
            $data = $query->row();
            return "" . $data->card_name;
        } else {
            return "n/a";
        }
    }

}

?>